package app.repositories.impl;

import java.util.List;

import javax.persistence.EntityManager;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import app.models.Convenio;
import app.repositories.ConvenioRepository;
import app.repositories.Repository;
import br.com.caelum.vraptor.ioc.Component;

@Component
public class ConvenioRepositoryImpl
    extends Repository<Convenio, Long>
    implements ConvenioRepository {

	private final String ID_CONVENIO = "id";
	
	public ConvenioRepositoryImpl(EntityManager entityManager) {
		super(entityManager);
	}
	
	@SuppressWarnings("unchecked")
	public List<Convenio> findLastConvenios() {
		Criteria criteria = createCriteria();
		
		criteria.addOrder(Order.asc(ID_CONVENIO));
		criteria.setMaxResults(10);
		
		return criteria.list();
	}
	
}